package com.cckp.leetcode;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * @author lijiasheng2  2021/10/31.
 */
public class MinStack {

    private Stack<Integer> que;
    private Stack<Integer> min;

    public MinStack() {
        que = new Stack<>();
        min = new Stack<>();
    }

    public void push(int val) {
        if(min.isEmpty()||val<=min.peek()){
            min.push(val);
        }
        que.push(val);
    }

    public void pop() {
        Integer a = que.pop();
        if(a.equals(min.peek())){
            min.pop();
        }
    }

    public int top() {
        return que.peek();
    }

    public int getMin() {
        return min.peek();
    }

    public static void main(String[] args) {
        MinStack stack = new MinStack();
        stack.push(1);
        stack.push(2);
        stack.top();
        stack.getMin();
        stack.pop();
        stack.getMin();
        stack.top();
    }
}

